<template>
  <div class="page">
	<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">

						<div class="layui-card-body">
							<div class="layui-form" lay-filter="">

								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">变量名 </label>
									    <div class="layui-input-inline" style="width: 380px;">
									      <input type="text" name="name" placeholder=""  v-model="itemData.name" autocomplete="off" class="layui-input a">									    
									    </div>
								  </div>
								</div>
								<div class="layui-form-item">
									<div class="layui-inline">
									    <label class="layui-form-label">变量值</label>
									    <div class="layui-input-inline" style="width: 380px;">
									      <input type="text" name="name" placeholder=""  v-model="itemData.value" autocomplete="off" class="layui-input a">									    
									    </div>
								  </div> 
								</div>
								<div class="layui-form-item">									
								    <label class="layui-form-label">域名名称</label>
								    <div class="layui-input-inline" style="width: 380px;">
								    <select name="memberGrade" lay-filter="pageDomainId" v-model="itemData.pageDomainId">	  									    																		      
								        <option :value='item.id' v-for="item in catlist">{{item.domain?item.domain:item.appId}}</option>
								       
								      </select>  
								    </div>
								 
								</div>
								
						   
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button class="layui-btn layui-btn-normal" lay-submit lay-filter="setmyinfo" @click="confirmOk">确认</button>										
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
  </div>
</template>
<script>

export default {
  name: 'leveladd',
  data () {
    return {
    	id:'',
			itemData:{
				pageDomainId:'',
				name:'',
				value:''
			},   
			catlist:''
    }
  },
  mounted(){
    var _this = this;     
  	window.getdates = this.getdates;  	
  	
  },
  methods: {
		getdates:function(data){
			if(data){
	      var _this=this;
	      this.id=data.id;
	      var url="/advert/aapi/v1.9/page-attribute/"+data.id;
	      ajaxRequest(url, 'GET', 'json','', function(ret, err){
					_this.itemData=ret.data;   
					_this.getcat()     
	      })
	   }
		 else{
		 	this.getcat()    
		 }
		},		
		getcat:function(){
			var url='/advert/aapi/v1.9/page-domain';
			var _this=this;
			ajaxRequest(url, 'GET', 'json','', function(ret, err){
				_this.catlist=ret.data;    
				_this.itemData.pageDomainId=ret.data[0].id
      })
		},
  	confirmOk:function(){
  		var _this = this;
			var len = $(".a").length;
			for(var i = 0; i < len; i++) {
				if($(".a").eq(i).val() == ''||$(".a").eq(i).val()<=0) {
					var msg = $(".a").eq(i).attr("placeholder");
					layer.msg('请输入正确的'+msg);
					return;
				}
			}
			
			if(_this.id){
			  var hat='PUT'
				var dates={
					"name": _this.itemData.name,
				  "pageDomainId":_this.itemData.pageDomainId,
				  "value":_this.itemData.value,
					 id:_this.id,
				}
			}else{
				var hat='POST'
				var dates={
				  "name": _this.itemData.name,
				  "pageDomainId":_this.itemData.pageDomainId,
				  "value":_this.itemData.value
				}
			}
			var url="/advert/aapi/v1.9/page-attribute" 
	    ajaxRequest(url,hat,'json',dates,function(ret,err){
			  layer.msg("操作成功");
			  setTimeout(function(){
			  	var index = parent.layer.getFrameIndex(window.name);
			    parent.layer.close(index);
		      parent.location.reload();
	      },1000)
			})
  	}
  },
  updated:function(){
  	var _this=this;
		layui.use('form', function(){
		  var form = layui.form;
		  form.render();
		  form.on('select(pageDomainId)', function(data){
				 	_this.itemData.pageDomainId=data.value;		 	
			});

		});

  },
}
</script>
<style scoped>
</style>
